var app = getApp();
Component({
  data: {
    windowWidth:0,
    slideWidth:'',//滑块宽
    slideLeft:0 ,//滑块位置
    totalLength:'',//当前滚动列表总长
    slideShow:false,
    slideRatio:'',
    categoryList:[],
    subjectList:[],
  },
  methods: {
    getdata(){
      let that=this;
      let data=app.cache['pages/home/home'].data;
      that.setData({
        categoryList:data.categoryList,
        subjectList:data.subjectList
      },function(){
        that.getRatio();
      })
    },
    getRatio(){
      let that=this;
      let len=that.data.categoryList.length; //放到项目中开启
      if (len<=5){
        that.setData({
          slideShow:false
        })
      }else{
        var _totalLength = len * 150;
        var _ratio = 100 / _totalLength * (750 / that.data.windowWidth);
        var _showLength = 750 / _totalLength * 100;
        that.setData({
          slideWidth:_showLength+'rpx',
          totalLength:_totalLength,
          slideShow:true,
          slideRatio:_ratio
        })
      }
    },
    getleft(e){
      this.setData({
        slideLeft:e.detail.scrollLeft * this.data.slideRatio+'rpx'
      })
    },
    // 小程序分类跳转
    clickItem(e) {
      let item = e.currentTarget.dataset.item;
      if(item.appLike){
          wx.navigateTo({
              url: '/'+item.appLike
          })
      }
    }
  },
  created: function(){
    let that=this;
    var systemInfo = wx.getSystemInfoSync();
    that.setData({
      windowWidth:systemInfo.windowWidth
    },function(){
      
    })
  },
  attached: function(){
    
  },
  ready: function(){
    
    
  },
  moved: function(){

  },
  detached: function(){

  },


});